package com.ardo.service.impl;

import com.ardo.entity.mall.Category;
import com.ardo.entity.mall.Pic;
import com.ardo.entity.mall.Product;
import com.ardo.entity.vo.GoodsPic;
import com.ardo.entity.vo.ProductDetail;
import com.ardo.mapper.BaseMapper;
import com.ardo.mapper.ProductMapper;
import com.ardo.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private BaseMapper baseMapper;

    @Resource
    private ProductMapper productMapper;

    @Override
    public String queryProductDetail(Integer id) {

        try{
            ProductDetail pd = new ProductDetail();
            //1.商品基础信息
            Product product = productMapper.queryProductBase(id);
            pd.setBasicInfo(product);

            //2.所属分类信息
            if(product!=null && product.getCategoryId()!=null){
                Category category = baseMapper.queryCategoryDetail(product.getCategoryId());
                pd.setCategory(category);
            }

            //3.详情内容-html片段
            pd.setContent(product.getDetail());

            GoodsPic gp = new GoodsPic();
            gp.setGoodsId(product.getId());
            gp.setPics(product.getPic());
            pd.setPics(gp);

            //图片库
            List<Pic> picList = baseMapper.queryPicList("product");
            if(picList!=null && picList.size()>0){
                String[] picArr = {};
                for (int i = 0; i < picList.size(); i++) {
                    picArr[i] = picList.get(i).getUrl();
                }
                pd.setPics2(picArr);
            }



        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
